package com.iwhalecloud.citybrain.flow.platform.manager.domain.model;


import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowNextNodeCandidateRepository;
import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

/**
 * @Description 流程下一节点候选人服务方法
 * @author liujinjian
 * @date 2021-10-22
 * @version 1.0
 */
@Data
@Service
public class FlowNextNodeCandidate implements Serializable, ApplicationContextAware {

    private static final long serialVersionUID = -2315163344796498547L;

    static FlowNextNodeCandidateRepository flowNextNodeCandidateRepository;

    /**
     * 主键Key
     */
    private Long id;

    /**
     * 流程实例编号
     */
    @NotNull(message = "流程实例编号不能为空")
    private String processInstanceId;

    /**
     * 节点编码
     */
    @NotNull(message = "节点编码不能为空")
    private String nodeCode;

    /**
     * 数据类型：STA，ORG，ROL
     */
    @NotNull
    private String dataType;

    /**
     * 编码
     */
    @NotNull
    private String code;

    /**
     * 名称
     */
    @NotNull
    private String name;

    /**
     * 来源节点编码
     */
    private String fromNodeCode;

    /**
     * 父执行id
     */
    private String parentExecutionId;

    /**
     * 任务ID
     */
    private String taskId;

    public void saveFlowNextNodeCandidate() {
        ModelNextNodeCandidateSettingsDomain candidate = new ModelNextNodeCandidateSettingsDomain();
        candidate.setNodeCode(this.nodeCode);
        candidate.setCode(this.code);
        candidate.setProcessInstanceId(this.processInstanceId);
        candidate.setDataType(this.dataType);
        candidate.setName(this.name);
        candidate.setFromNodeCode(this.fromNodeCode);
        candidate.setParentExecutionId(parentExecutionId);
        candidate.setTaskId(this.taskId);
        flowNextNodeCandidateRepository.save(candidate);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        flowNextNodeCandidateRepository = applicationContext.getBean(FlowNextNodeCandidateRepository.class);
    }
}